package com.self.cgqcompose.ui.components.areacode

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.self.cgqcompose.beans.AreaBlock
import kotlinx.coroutines.delay

@Composable
fun AreaCode74(data: AreaBlock) {
    val pagerState = rememberPagerState { data.data.data.size }
    // 自动轮播逻辑
    LaunchedEffect(Unit) {
        if (data.data.data.isNotEmpty()) {
            while (true) {
                delay(3000L) // 每 3 秒切换一次
                val nextPage = (pagerState.currentPage + 1) % data.data.data.size
                pagerState.animateScrollToPage(nextPage)
            }
        }
    }
    HorizontalPager(pagerState,  modifier = Modifier
        .padding(horizontal = 8.dp)) { page ->
        AsyncImage(
            model = data.data.data[page].cover, // 假设 tab 对象有一个 iconUrl 属性
            contentDescription = "tab icon",
            modifier = Modifier
                .fillMaxWidth()
                .aspectRatio(645/120f)
        )
    }
}